package com.sc.producer.controller;

import com.sc.producer.entity.Goods;
import com.sc.producer.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GoodsController {

    @Autowired(required = false)
    private GoodsService goodsService;

    @RequestMapping(value = "/goodss",method = RequestMethod.GET)
    public List<Goods> findGoods()
    {
        return  goodsService.findAllGoods();
    }


    @RequestMapping(value = "/goods/{id}",method = RequestMethod.GET)
    public Goods findOneGoods(@PathVariable(value = "id") int id)
    {
        return  goodsService.findGoodsById(id);
    }

    @RequestMapping(value = "/goods",method = RequestMethod.POST)
    public Goods addGoods(@RequestBody Goods goods)
    {
        return  goodsService.addGoods(goods);
    }

    @RequestMapping(value = "/goods",method = RequestMethod.PUT)
    public Goods updateGoods(@RequestBody Goods goods)
    {
        return  goodsService.updateGoods(goods);
    }

    @RequestMapping(value = "/goods/{id}",method = RequestMethod.DELETE)
    public Boolean deleteGoods(@PathVariable(value = "id") int id)
    {
        return  goodsService.deleteGoodsById(id);
    }
}
